<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>将 html 元素中文本内容用 html 元素属性值对应的 JavaScript 变量替换</title>
</head>
<body>
<div id="change" class="change">
    <h1 text="text" style="background-color: red">Hello, World!</h1>
    <h1 text="text" style="background-color: green">Hello, World!</h1>
</div>

<script>
    let text = "Hello, Vue!"
    let elements = document.querySelectorAll("#change>h1");
    for (let i = 0; i < elements.length; i++) {
        // console.log(elements[i]);
        let attribute = elements[i].getAttribute("text");
        console.log(attribute);

        elements[i].innerText = eval(attribute);
    }

</script>

</body>
</html>